
************************************************************************************************************************************************
****************************** REPLICATION CODE: RELIGION AND BRAZILIAN POLITICS 
****************************** 2019. Cambridge University Press
****************************** By Amy Erica Smith (amyericas@gmail.com) 

****************************** ANALYSIS OF AMERICASBAROMETER DATA



****************************************** VARIABLE CODING **************************************************************************************
use "C:\Users\aesmith2\Dropbox\Work\Data\LAPOP\Individual country datasets\Brazil\brazil_lapop_dims final 2007 v5.dta", clear
foreach var of varlist * {
	local new = lower("`var'") 
	rename `var' `new' 
}
recode year 2006=2007
append using "C:\Users\aesmith2\Dropbox\Work\Data\LAPOP\Individual country datasets\Brazil\brazil_lapop_dims_2008_final_data_set_v10.dta", force
append using "C:\Users\aesmith2\Dropbox\Work\Data\LAPOP\Individual country datasets\Brazil\Brazil lapop_2010.dta", force
	replace year = 2010 if year == .
	replace wt = 1 if year == 2008 | year == 2010
append using "C:\Users\aesmith2\Dropbox\Work\Data\LAPOP\Individual country datasets\Brazil\54861031Brazil LAPOP AmericasBarometer 2012 Rev1_W.dta", force
append using "C:\Users\aesmith2\Dropbox\Work\Data\LAPOP\Individual country datasets\Brazil\523605379Brazil LAPOP AmericasBarometer 2014 v1_W.dta", force
replace year = 2014 if year == .
append using "C:\Users\aesmith2\Dropbox\Work\Data\LAPOP\Individual country datasets\Brazil\dirty_GM v07172017_Brazil 2017 only.dta", force
replace year = 2017 if year == .
lab lang en
summ year
g year2 = (year-r(min))/(r(max)-r(min))

recode q5a q5b ing4 b1 b2 b3 b4 b6 e5 e11 e15 d1 d2 d3 d4 d5 d6 ed q2 q3 q3c vs18 vs19 ///
	r4 r5 r6 r7 r15 r18 r16 vb10 rac2 (88 98 988 =.)

********************* CODE VARIABLES
recode brarel1 (1/5 = 0) (6/10 = 1), g(brarel_dichot)
lab var brarel_dichot "Agrees Clergy Endorsements Justified"

replace brarel1 = (brarel1-1)/9

recode q3c (1=1) (2 5 =2) (4 11 = 3) (6 12 3 7 77 1501 = 4) if year >= 2012 , g(rel)
lab def rel 1 "Catholic" 2 "Evangelical/Pentecostal" 3 "None" 4 "Other Religion"
lab val rel rel
lab var rel "Religious Affiliation"
	replace rel = vs18 if year == 2007
	recode rel (8 = 1) (2 3 = 2) (12 13 = 3) (1 4 5 6 7 9 10 11 = 4) if year == 2007
	replace rel = q3 if year == 2008
	recode rel (1=1) (2 5 = 2) (13 4 = 3) (3 6 7 10 11 = 4) if year == 2008
	replace rel = q3c if year == 2010
	recode rel (1 = 1) (2 5 = 2) (4 11 = 3) (3 6 7 8 10 12 = 4) if year == 2010
capture nicelylabelleddummies rel, g(rel)
capture tab rel, g(rel)
recode rel (1=1)(2/4 = 0), g(catholic)
recode rel (2=1)(1 3 4 = 0), g(evangelical)
recode rel (3=1)(1 2 4 = 0), g(none)
recode rel (4=1)(1 2 3 = 0), g(otherreligion)
recode rel (1=1) (2=2) (3/4 = 3), g(relr)
	lab def relr 1 "Catholic" 2 "Evangelical/Pentecostal" 3 "None/Other"
	lab val relr relr
	lab var relr "Religious Affiliation"
	

g q5br = (4-q5b)/3
lab var q5br "Importance of Religion"

replace q5a = 6-vs19 if year == 2007
recode q5a (. = 1) if year == 2008
g q5ar = (5-q5a)/4
lab var q5ar "Frequency of Church Attendance"

recode brarel2 (2=0), g(clergy_impeachment)

recode brarel2a (3 4 .a .b .c = 0) (1 2 = 1), g(clergy_impeach_partisan)
recode brarel2a (1 2 .a .b .c = 0) (3 4 = 1), g(clergy_impeach_nonpartisan)
recode brarel2a (2 3 4 .a .b .c = 0) (1 = 1), g(clergy_impeach_afavor)
recode brarel2a (1 3 4 .a .b .c = 0) (2 = 1), g(clergy_impeach_contra)

************ POLITICAL ATTITUDES
capture drop ing4r
g ing4r = (ing4-1)/6
	lab var ing4r "Support for Democracy"

recode ing4 (1/4 = 0) (5/7 = 1), g(ing4d)
	lab var ing4d "Support for Democracy"

capture drop psa5*
egen systemsupport = rowmean(b1 b2 b3 b4 b6)
	replace systemsupport = (systemsupport-1)/6
	lab var systemsupport "System Support"

egen contentiousparticipation = rowmean(e5 e11 e15)
	replace contentiousparticipation = (contentiousparticipation-1)/9
	lab var contentiousparticipation "Support for Contentious Participation"
recode contentiousparticipation (1/5=0) (5.1/10=1), g(contentiousd)
lab var contentiousd "Support for Contentious Participation"

capture drop tol
egen tol = rowmean(d1 d2 d3 d4)
	replace tol = (tol-1)/9
	lab var tol "Political Tolerance"
	
capture drop d5r
g d5r = (d5-1)/9

capture drop tolr
g diff = d5-d3
g tolr = tol
	replace tolr = d5r if diff < 0 & tol < . & d5r < .

recode l1 (88 98 = .c)
recode l1 (1/3 = 1) (4/.c = 0), g(leftist)
recode l1 (8/10 = 1) (1/7 ./.c = 0), g(rightist)
recode l1 (1/3 8/10 = 0) (4/7 .a .b .c = 1), g(centrist)
recode l1 (1/3=0) (4/7 .a .b .c = .5) (8/10 = 1), g(leftist_rightist)
recode l1 (. .a .b .c = 5.5), g(l1r)

drop it1r
recode it1 (88 98 = .)
g it1r = (4-it1)/3

recode brait1 (88 98 = .)
g brait1r = (4-brait1)/3

capture drop pol1r
recode pol1 (88 98 = .)
g pol1r = (4-pol1)/3

recode vb10 (2=0), g(haspid)
g petista = 0 if haspid < .
	replace petista = 1 if sep2 == 13 & year == 2007
	replace petista = 1 if vb11 == 1513 & year == 2008
	replace petista = 1 if vb11 == 1501 & year > 2008
	replace petista = 1 if vb11_16 == 1501 & year == 2017
	

************ POLICY ISSUES
recode gen8 (1=1) (2 3 = 0), g(gaymen) 
	lab var gaymen "Accepts Homosexuality"
g d6r= (d6-1)/9
	lab var d6r "Support for Gay Marriage"
recode w14a (2=0), g(abortion)
	lab var abortion "Abortion Justified for Mother's Health"

**** ros1: country owner of most important industries
	**** ros2: country responsible for people's well-being
	**** ros3: country responsible for creating jobs
	**** ros4: strong policies to reduce inequality b/t rich and poor
	**** ros5: country responsible for retirement pensions
	**** ros6: country responsible for health care services
capture drop ros*r
forvalues i = 1/6 {
	recode ros`i' (88 98 = .)
	g ros`i'r = (ros`i'-1)/6
} 
lab var ros1r "Owner of Most Important Industries"
lab var ros2r "Responsible for People's Well-Being"
lab var ros3r "Responsible for Creating Jobs"
lab var ros4r "Reducing Inequality"
lab var ros5r "Responsible for Pensions"
lab var ros6r "Responsible for Health Care"	
factor ros1r ros2r ros3r ros4r ros6r if year == 2012
	alpha ros1r ros2r ros3r ros4r ros6r if year == 2012, item
egen ros = rowmean(ros2r ros3r ros4r ros6r)
egen rosr = rowmean(ros1r ros4r) //this one maintains the same items over time


foreach var in gen6 gen7 {
	recode `var' (1=1) (2 = .75) (6=.5) (3=.25) (4=0) if year == 2007 , g(`var'r)
}
egen gender = rowmean(gen6r gen7r)
	lab var gender "Women in LF"

g womenleaders = (vb50-1)/3	
	
replace l1 = (l1-1)/9	

recode env1 (3=.5) (2=0) (1=1)
	replace env1 = (env1c-1)/6 if year == 2017
	recode env1 (0/.4 = 0) (.6/1 = 1)

replace rac2 = (rac2-1)/6
	
****** network ties to politicians and clientelism	
recode clien1 (88 98 = .) (3 = 0) (1 2 = 1), g(clien1r)
recode snw1a 2=0
	
************** DEMOGRAPHICS 
replace tamano = tamanho if tamano >= . & tamanho < .
g tamanor = (5-tamano)/4
lab var tamanor "Size of Place of Residence"

recode ur (2=0), g(urban)
lab var urban "Urban"

factor r4 r5 r6 r7 r15 r18 r16
alpha r4 r5 r6 r7 r15 r18 r16
egen hhgoods = rowtotal (r4 r5 r6 r7 r15 r18 r16)
	replace hhgoods = hhgoods/9
lab var hhgoods "Index of Household Goods"

capture drop edad
recode q2 (16/25=1) (26/35=2) (36/45=3) (46/55=4) (56/65=5) (66/110=6), g(edad)
lab def edad 1 "16-25" 2 "26-35" 3 "36-45" 4 "46-55" 5 "56-65" 6 "66+", modify 
lab val edad edad
lab var edad "Age Group"
g edad2 = (edad-1)/5

capture drop edr
replace ed = vs2 if year == 2007
recode ed (0 = 0) (1/6 = 1) (7/12 = 2) (13/21 = 3), g(edr)
	lab def edr 0 "None" 1 "Primary" 2 "Secondary" 3 "Higher", modify
	lab val edr edr
recode edr (0=1) (1/3 = 0), g(noeducation)

capture drop mujer
g mujer = q1-1	
recode q12 (1/23 = 1) (88 98 = .), g(haskids)
	replace q12 = 1 if vs15 < 77 
	replace q12 = 0 if vs15 == 77 

capture drop white 
capture drop afro
g white = etid == 1	if year > 2007
g afro = etid == 4 | etid == 5 if year > 2010
	replace afro = 1 if etid == 2 | etid == 4 & (year == 2008 | year == 2010)
	replace afro = 0 if etid == 1 | etid == 3 | etid > 4 & (year == 2008 | year == 2010)
	

****************************** POLITICAL PARTICIPATION
* prot1: ever participated in any protest: 2007 & 2008
* prot2: participated in any protest in last year: 2007 and 2008
* prot3: participated in any protest in last year: 2010-2014
capture drop prot3r
recode prot3 (2=0) (88=.a) (98=.b), g(prot3r)
	replace prot3r = 1 if prot2 == 1 | prot2 == 2
	replace prot3r = 0 if prot2 == 3 | (prot1 > 2 & year < 2010)
	lab var prot3r "Protest Participation"
****** Other PROTEST MEASURES
* prot4: how many times participated: 2010 & 2012
* prot6: participated in blocking any street: 2012
* prot7: signed a petition: 2012
* prot8: political info on social media: 2012
* braprot9: politically motivated consumer choices
* braprot3b: strike/work stoppage: 2014
* braprot3c: likelihood of participating in CM protests: 2014
* bracid2: protests make gov pay attention: 2014
g braprot3cr = (4-braprot3c)/3 
recode braprot3c (3 4 = 0) (1 2 = 1), g(braprot3crr)
recode braprot3c (2 3 4 = 0) (1 = 1), g(braprot3crrr)
g bracid2r = (bracid2-1)/6 
****** COMMUNITY PARTICIPATION
* cp5: community problem solving (2007-2014)
		**** NOTE: In 2007, cp5 is dichotomous
* cp7: pta (all years)
	* cp7l: leadership (2012)
* cp8: community association (all years)
	* cp8l: leadership (2012)
* cp9: trade association (2007-2012)
* cp10: union (sindicato) (2007 & 2008)
* cp13: party meeting (all years)
* cp14: local municipal development council (2007)
* cp20: women's group (2008-2014)
* cp21: sport's club (2012)
* vb2: turnout
capture drop cp*r community vb2r
recode cp5 2 = 4 if year == 2007
foreach var in cp5 cp7 cp8 cp9 cp13 cp20 {
	recode `var' (88/99 = .)
	recode `var' (1 2 3 = 1) (4 = 0), g(`var'dichot) 
	g `var'r = (4-`var')/3 
}
egen community = rowmean(cp5r cp8r)
recode community (.1/1=1), g(communitydichot)
recode vb2 (2=0) (88/99=.), g(vb2r)

recode prot6 (2=0), g(baixoassinado)

***************************** CONTACTING
* np2: formal petition for local assistance (2007-2014)
* cp4a: request for local assistance (2007-2014)
* cp2: request for assistance from senator or fed deputy (2007-2012)
* cp4: request for assistance from gov office/ministry (2007-2012)
foreach var in np2 cp4a cp2 cp4 {
	capture drop `var'r
	recode `var' (8/99 = .)
	recode `var' (2 = 0), g(`var'r) 
}
egen localcontacting = anycount(np2 cp4a), values(1)
	recode localcontacting (2=1)
egen anycontacting = anycount(np2r cp4ar cp2r cp4r), values(1)
	recode anycontacting (2/6=1)
egen nonlocalcontacting = anycount(cp2r cp4r), values(1)
	recode nonlocalcontacting (2/6=1)

**************************** VOTE CHOICE
* vb3n: vote choice in 2014

recode vb3n (0/1502 1509 .a .b .c = 0) (1503 = 1) if year == 2014, g(marinavote)



************************************************************************************************************************************************
************************************************************************************************************************************************
****************************************** ANALYSIS ********************************************************************************************


****************** FIGURE 1.2: who switches away from Catholicism?
preserve
mlogit rel year2 edad2 b1503.estratopri tamanor mujer afro hhgoods i.edr leftist rightist it1r pol1r  
parmest, norestore 
drop if eq == "Catholic" | parm == "_cons" | parm == "6b.edad" | parm == "0b.edr" | parm == "1503b.estratopri" | parm == "2008b.year"
sencode eq, replace
	lab def eq 1 "Protestant/Pentecostal" 2 "No Religion" 3 "Other Religion", modify
	lab val eq eq
g xxx = _n 
sencode parm, replace gsort(-xxx)
	lab def parm 17 "Year (2008-2017)" 16 "Age Group" 15 "North Region" 14 "Northeast Region" 13 "Southeast Region" 12 "South Region" ///
		11 "Size of Locality" 10 "Female" 9 "Afro-Descendant" 8 "Household Wealth" 7 "Primary Education" 6 "Secondary Education" ///
		5 "Higher Education" 4 "Leftist" 3 "Rightist" 2 "Interpersonal Trust" 1 "Political Interest" , modify
	lab val parm parm
	drop xxx
graph twoway (scatter parm estimate, mcolor(black)) ///
			(rspike min95 max95 parm, lcolor(black) horizontal), ///
	by(eq, col(3) graphregion(fcolor(white) lcolor(black))	legend(off) ///
		note("Coefficients estimate each variable's impact on the likelihood of reporting a religious affiliation, versus Catholic." " " ///
			"Source: LAPOP AmericasBarometer 2008-2014 Waves. Coefficients and 95% confidence intervals from multinomial logistic" ///
			"regression models. Baseline categories are no education and Center-West region. All variables coded from 0 to 1.") 	) ///
	ylabel(1(1)17, valuelabel angle(horizontal) labsize(small)) xlabel(-2(1)2) xline(0, lcolor(gs10)) plotregion(lcolor(black)) ///
	ytitle("") xtitle("") xsize(6.5)	
restore
****************** FIGURE 1.2: who switches away from Catholicism?


************ FIGURE 6.1: POLICY ATTITUDES, OVER TIME, BY RELIGION, AmericasBarometer
foreach dv in d6r rosr env1 {
	svy: reg `dv' i.year##i.relr 
	margins year#relr, post
	parmest, saving(`dv', replace) idstr(`dv')
	}
foreach dv in abortion {
	svy: logit `dv' i.year##i.relr 
	margins year#relr, post
	parmest, saving(`dv', replace) idstr(`dv')
	} 
preserve
dsconcat d6r abortion rosr env1 
rename idstr dv
	sencode dv, replace
	lab def dv 1 "Same-Sex Marriage" 2 "Abortion (Mother's Health)" 3 "Economic Role of State" 4 "Environment (Versus Economy)", modify
egen rel = seq(), f(1) t(3)	
egen year = ends(parm), punct(.) head
	destring year, replace
graph twoway (rcap min95 max95 year if rel == 2 | rel == 3, lcolor(gs10) lwidth(thin)) ///
			(rcap min95 max95 year if rel == 1, lcolor(black) lwidth(thin)) ///
			(connected estimate year if rel == 1, lcolor(black)  lwidth(thick) lpattern(longdash) mcolor(black)) ///
			(connected estimate year if rel == 2, lcolor(gs8) lwidth(thick) lpattern(longdash) mcolor(gs8)) ///
			(connected estimate year if rel == 3, lcolor(gs10) mcolor(gs10) msymbol(D)) , ///
	by(dv, col(2) 	graphregion(fcolor(white) lcolor(black))  yrescale ///
			note("Source: AmericasBarometer by LAPOP, Brazil. Estimates adjusted for design" ///
				"effects. See text and online appendix for dependent variables.", span)  ) ///
	legend(order(3 "Catholic" 4 "Evangelical" 5 "None/Other" ) span size(small) col(3) ) ///
	ysize(4) xlabel(2008 2010 2012 2014 2017) ///
	xtitle("Year", margin(small)) ytitle("Level of Support") plotregion(lcolor(black)) 
restore	
foreach dv in abortion d6r rosr env1  {
	rm `dv'.dta
}
************ END FIGURE 6.1: POLICY ATTITUDES, OVER TIME, BY RELIGION, AmericasBarometer

	
************ FIGURE 6.2: PETISMO, OVER TIME, BY RELIGION, AmericasBarometer
preserve
svy: logit petista i.year##i.relr 
	margins year#relr, post
	parmest, norestore level(86)
egen rel = seq(), f(1) t(3)	
egen year = ends(parm), punct(.) head
	destring year, replace
foreach var in estimate min86 max86 {
	replace `var' = `var'*100
}
graph twoway (rcap min86 max86 year if rel == 2 | rel == 3, lcolor(gs10) lwidth(thin)) ///
			(rcap min86 max86 year if rel == 1, lcolor(black) lwidth(thin)) ///
			(connected estimate year if rel == 1, lcolor(black)  lwidth(thick) lpattern(longdash) mcolor(black)) ///
			(connected estimate year if rel == 2, lcolor(gs8) lwidth(thick) lpattern(longdash) mcolor(gs8)) ///
			(connected estimate year if rel == 3, lcolor(gs10) mcolor(gs10) msymbol(D)) , ///
	graphregion(fcolor(white) lcolor(black))  ///
	note("Source: AmericasBarometer by LAPOP, Brazil. Estimates adjusted for design effects.", span)   ///
	legend(order(3 "Catholic" 4 "Evangelical" 5 "None/Other" ) span size(small) col(3) ) ///
	xlabel(2007 2008 2010 2012 2014 2017) ///
	xtitle("Year", margin(small)) ytitle("Predicted Percentage Petista")  
restore	
************ END FIGURE 6.2: PETISMO, OVER TIME, BY RELIGION, AmericasBarometer


******************** FIGURE 8.4. CHURCHES AND TOLERANCE of gays running for office, AmericasBarometer
preserve
svy: mean d5r, over(rel)
parmest, norestore
sencode parm, replace
	rename parm rel
	lab val rel rel
graph twoway (bar estimate rel, lcolor(black) fcolor(gs11) barwidth(.5)) ///
			 (rspike min95 max95 rel, lcolor(black)) , ///
	graphregion(fcolor(white) lcolor(white)) ytitle("Tolerance of the Rights of Gays" "to Run for Office (0-1 scale)", margin(medsmall)) ///
	xtitle("Religious Affiliation", margin(medium)) ylabel(.4(.1).7, grid labels) ymlabel(.45(.1).75, grid nolabels noticks) ///
	xlabel(1(1)4, valuelabel) legend(off) name(part1, replace) fxsize(70)
restore
preserve
replace q5ar = q5ar*4
svy: reg d5r b3.rel##c.q5ar i.edr hhgoods i.edad mujer tamanor i.year
lincom q5ar + 1.rel#c.q5ar
lincom q5ar + 2.rel#c.q5ar
lincom q5ar + 4.rel#c.q5ar
margins, at(rel=(1 2 3 4) q5ar=(1 2 3 4 5)) post
parmest, norestore
egen q5ar = seq(), f(1) t(5)
	lab def q5ar 1 "Never" 2 "Once/Twice a Year" 3 "Monthly" 4 "Weekly" 5 "> Weekly"
	lab val q5ar q5ar
egen rel = seq(), f(1) t(4) block(5)
	lab def rel 1 "Catholic" 2 "Evangelical/Pentecostal" 3 "No Religion" 4 "Other Religion", modify
	lab val rel rel
graph twoway (connected estimate q5ar if rel == 1, lcolor(gs8)  lwidth(thick) lpattern(longdash) mcolor(gs8) msymbol(Dh)) ///
			(connected estimate q5ar if rel == 2, lcolor(black) lwidth(thick) lpattern(dashdot) mcolor(black)) ///
			(connected estimate q5ar if rel == 3, lcolor(gs8)  lwidth(thick) mcolor(gs8)) ///
			(connected estimate q5ar if rel == 4, lcolor(black) mcolor(black)), ///
	ytitle("") ylabel(.4(.1).7, grid labels) ymlabel(.45(.1).75, grid nolabels noticks) ///
	xlabel(, valuelabel) xscale(r(1 5.1)) xtitle("Frequency of Church Attendance", margin(medsmall)) ///
	graphregion(fcolor(white) lcolor(white)) ///
	legend(order(4 "Other Religion" 3 "No Religion" 1 "Catholic" 2 "Evangelical/" "Pentecostal" ) size(small) symxsize(medium)) name(part2, replace)
restore	
graph combine part1 part2, col(2) ///
	graphregion(fcolor(white) lcolor(black)) xsize(6.5) iscale(.9) ///
	note("Source: AmericasBarometer by LAPOP, Brazil waves 2007-2017. The right pane presents predicted values from model" ///
	"controlling for education, household wealth, age, gender, size of place of residence, and year. Estimates adjusted for" ///
	"design effects.", span)
******************** END FIGURE 8.4. CHURCHES AND POLITICAL TOLERANCE, AmericasBarometer


************** FIGURE 8.5: PROTEST PARTICIPATION BY RELIGION, AmericasBarometer 
forvalues i = 1/3 {
	preserve
	recode rel (4=3)
	recode prot3r(1=100)
	tempfile tf`i'
	svy: mean prot3r if rel == `i', over(year)
	parmest, norestore
	g rel = `i'
	save `tf`i'', replace
	restore
}	
preserve
dsconcat `tf1' `tf2' `tf3' 
sencode parm, replace
	rename parm year
	lab def year 1 "2007" 2 "2008" 3 "2010" 4 "2012" 5 "2014" 6 "2017"
	lab val year year
graph twoway (connected estimate year if rel == 1, lcolor(gs8)  lwidth(thick) lpattern(longdash) mcolor(gs8)) ///
			(connected estimate year if rel == 2, lcolor(black) lwidth(thick) lpattern(dashdot) mcolor(black)) ///
			(connected estimate year if rel == 3, lcolor(gs8)  lwidth(thick) mcolor(gs8)) , ///
	graphregion(fcolor(white) lcolor(black)) ytitle("Protest in Past Year (Percent)", margin(medium)) xtitle("") ///
	ylabel(0(5)15, grid labels) xlabel(1(1)6, valuelabel) ///
	legend(order(1 "Catholic" 2 "Evangelical/" "Pentecostal" 3 "No/Other" "Religion") col(3) size(small)) ///
	note("Source: AmericasBarometer by LAPOP, Brazil. Estimates adjusted for design effects.", span)
************** END FIGURE 8.5: PROTEST PARTICIPATION BY RELIGION, AmericasBarometer 

	
